<template>
  <div class="comment">
    <div class="comment-wrap">
      <div class="header">
        <h3>大家都在说</h3>
        <span>生活,没有统一标准</span>
      </div>
      <div class="comment-main">
        <div
          class="comment-item"
          v-for="(comment, index) in newCommentList.slice(0, 2)"
          :key="index"
        >
          <div class="item-top" @click="toDetail(comment.id)">
            <img :src="comment.listPicUrl" alt="" />
          </div>
          <div class="item-bottom"></div>
          <div class="item-comment">
            <div class="comment-area">
              <div class="comment-date">
                <span class="name">{{ comment.frontUserName }}</span>
                <span class="date">
                  {{ comment.createTime }}
                </span>
              </div>
              <div class="comment-goods">
                <span class="title">{{ comment.name }}</span>
                <span class="price">￥{{ comment.retailPrice }}</span>
              </div>
              <div class="comment-content">{{ comment.content }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import dayjs from 'dayjs'
export default {
  name: 'Comment',
  props: ['commentList'],
  data() {
    return {
      newCommentList: [],
    }
  },
  methods: {
    // 跳转到对应的商品详情页
    toDetail(id) {
      this.$router.history.push({
        path: '/Detail',
        query: {
          id,
        },
      })
    },
  },

  watch: {
    commentList: {
      handler(commentList) {
        this.newCommentList = commentList
        this.newCommentList.forEach((item) => {
          item.createTime = dayjs(item.createTime).format('YYYY-MM-DD HH:mm:ss')
        })
      },
      immediate: true,
    },
  },
}
</script>

<style lang="less" scoped>
.comment {
  width: 100%;
  padding-top: 30px;
  background-color: #f4f0ea;
  .comment-wrap {
    width: 1090px;
    margin: 0 auto;
  }
}
.header {
  margin-top: 30px;
  padding-bottom: 20px;
  display: flex;
  align-items: flex-end;
  h3 {
    font-size: 28px;
    margin-right: 20px;
  }
  span {
    font-size: 14px;
    padding-bottom: 3px;
  }
}
.comment-main {
  padding-bottom: 50px;
  display: flex;
}
.comment-item {
  position: relative;
  width: 355px;
  height: 490px;
  background-color: #fff;
  margin-right: 10px;
  display: flex;
  flex-direction: column;
  .item-top {
    width: 355px;
    height: 355px;
    overflow: hidden;
    img {
      width: 100%;
      height: 100%;
      transition: all 0.5s linear 0.3s;
    }
  }
  .item-bottom {
    width: 355px;
    height: 135px;
  }
  .item-comment {
    position: absolute;
    bottom: 0px;
    left: 5px;
    width: 345px;
    height: 190px;
    background-color: #fff;
  }
}
.comment-item:hover {
  .item-top {
    img {
      transform: scale(1.1);
    }
  }
}
.comment-area {
  padding: 20px 15px;
  .comment-date {
    font-size: 13px;
    color: #999;
    margin-bottom: 10px;
    .name {
      padding-right: 10px;
    }
  }
  .comment-goods {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    .title {
      width: 190px;
      font-size: 16px;
      font-weight: bold;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .price {
      color: #b4a078;
      font-size: 13px;
      margin-right: 15px;
    }
  }
  .comment-content {
    height: 80px;
    font-size: 13px;
    overflow: hidden;
  }
}
</style>
